package com.example.demo;

import java.util.ArrayList;
import java.util.List;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;

@RestController
@RequestMapping
public class DemoController {

  @PostMapping(value = "/open/post")
  public Object invoke(@RequestBody JSONObject request) {
    if (request.containsKey("merchantId")) {
      Response01 response01 = new Response01();
      response01.setCode("response01");
      return response01;
    }
    
    if (request.containsKey("list")) {
      List<List<Response02>> response01 = new ArrayList<>();
      List<Response02> l = new ArrayList<Response02>();
      Response02 r = new Response02();
      r.setCode("response02");
      l.add(r);
      
      response01.add(l);
      return response01;
    }
    
    Response02 response02 = new Response02();
    response02.setCode("response02");
    return response02;
  }
  
  
  @PostMapping(value = "/open/error")
  public ResponseEntity<?> error() {
    JSONObject body = new JSONObject();
    body.put("messge", "ttt");
    return ResponseEntity.status(500).body(body);
  }
  
}
